<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script type="text/javascript" src="./lib/layui/layui.js"
            charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
    <!-- <form class="layui-form">-->
            <div class="layui-form-item">
                <label for="id" class="layui-form-label"> <span
                        class="x-red"></span>ID
                </label>
                <div class="layui-input-inline">
                    <input type="telephone" id="id" name="id" readonly
                           lay-verify="id" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="professorname" class="layui-form-label"> <span
                        class="x-red"></span>姓名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="professorname" readonly name="professorname"
                           lay-verify="professorname" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-card-body ">
                <table class="layui-table" width="100%" height="50%"
                       lay-data="{page:false,id:'queryTable',toolbar: '#toolbarDemo'}"
                       lay-filter="queryTable" id="queryTable">
                    <thead>
                    <tr>
                        <th lay-data="{type:'checkbox'}">ID</th>
                        <th lay-data="{field:'id', width:80, sort: true}">编号</th>
                        <th
                                lay-data="{field:'startdate', width:120, sort: true, }">开始时间</th>
                        <th lay-data="{field:'enddate',  minWidth: 120}">结束时间</th>

                        <th lay-data="{field:'employcompany',  minWidth: 140}">公司</th>
                        <th lay-data="{field:'job', sort: true, }">职务</th>
                        <th lay-data="{field:'jobduty', sort: true }">岗位</th>
                        <th lay-data="{templet: '#newsListBar',minWidth:200}">操作</th>
                    </thead>
                </table>
            </div>
         <script type="text/html" id="toolbarDemo">
             <div class = "layui-btn-container" >
                 <button class = "layui-btn layui-btn-sm" lay-event = "addNewUser" >
                     <i class="layui-icon">&#xe654;</i>
                     添加新记录
                 </button>
               <!--  <button class = "layui-btn layui-btn-sm" lay-event = "delBatch" > 批量删除 </button>-->
                 <!--
                 <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button >
                 <button class = "layui-btn layui-btn-sm" lay-event = "isAll" > 验证是否全选</button>-->
             </div >
         </script>

            <script type="text/html" id="newsListBar">
                <a class="layui-btn layui-btn-xs" id="edit" lay-event="edit">编辑</a>
                <a class="layui-btn layui-btn-xs layui-btn-danger" id="del" lay-event="del">删除</a>
            </script>


            <div class="layui-form-item">
                <label  class="layui-form-label"></label>
                <label  class="layui-form-label"></label>
                <button class="layui-btn" lay-filter="back" id="back">返回</button>
            </div>
        <!--</form>-->
    </div>


</div>
<script>layui.use([ 'form', 'laydate','layer', 'jquery','table' ],
    function() {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer,
            laydate=layui.laydate,
            table=layui.table;

        laydate.render({
            elem : '#enterdate' //指定元素
            ,trigger: 'click'
        });


        var id=location.search.substring(1);
        var pro;
        $.get("professorGet.do",{id:id},function(obj){
            pro=obj;
            for (var i in obj) {
                $("#" + i).val(obj[i]);
            }
            //工作记录单独处理
            //form.render();//重绘表单
            //alert(JSON.stringify(obj.workhistory));
            form.render();
            //table.render({elem:'#queryTable',data:obj.workhistory});
            table.reload("queryTable",{
                data:obj.workhistory
            });
        });

        //监听头部事件
        table.on('toolbar(queryTable)', function(obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            alert(">>>>>>>>>>>>>>>>>>>>"+obj.event);
            switch (obj.event) {
                case 'addNewUser':
                    //可以通过layer.data传递数据
                   // alert(">>>>>>>>>>>>>>>>>>>>"+JSON.stringify(pro));
                    layui.sessionData("professor",{key:'data',value:{'id':pro.id,'professorname':pro.professorname}});

                    //xadmin.set_cate_data(pro);

                    xadmin.open('添加工作记录', './history-add.html', 600, 400);
                   /* var index = layui.layer.open({
                        title: '添加工作记录',
                        type: 2,
                        content: "history-add.html"
                    });*/
                    break;
            };
            event.stopPropagation();
            return false;
        });
        //监听表单back

        //监听单元行
        table.on('tool(queryTable)',function(obj){
            var layEvent = obj.event;
            var data=obj.data;

            if(layEvent=="edit"){
                edit(data);
            }else if(layEvent=="del"){
                del(this,data);
            }
            event.stopPropagation();
            //return false;
        });
        function del(obj,data){
            layer.confirm('确定删除选中的工作记录？', {
                icon : 3,
                title : '提示信息'
            }, function(index) {
                $.getJSON("workhistoryDel.do", {
                hisid:data.id,id:id
                }, function(d) {
                    if (d.msg) {
                        //location.reload();//不刷新，直接删除tr
                        $(obj).parents("tr").remove();
                        layer.close(index);
                    } else {
                        layer.alert("删除失败");
                    }
                });
            })
        }
        //监听按钮
        $(document).on('click','#back',function(){
            xadmin.close();
        });
    });
</script>

</body>

</html>